<script type="text/javascript" src="<?=WEBSITE_URL?>/js/tiny_mce/tiny_mce.js"></script>
<script>
tinyMCE.init({
		// General options
		mode : "exact",
                elements: "elm1",
		theme : "advanced",
                verify_html : false,
                cleanup: false,
                
		plugins : "autolink,lists,pagebreak,style,layer,table,save,advhr,advimage,advlink,emotions,iespell,inlinepopups,insertdatetime,preview,media,searchreplace,print,contextmenu,paste,directionality,fullscreen,noneditable,visualchars,nonbreaking,xhtmlxtras,template,wordcount,advlist,autosave,visualblocks",

		// Theme options
		theme_advanced_buttons1 : "save,newdocument,|,bold,italic,underline,strikethrough,|,justifyleft,justifycenter,justifyright,justifyfull,styleselect,formatselect,fontselect,fontsizeselect",
		theme_advanced_buttons2 : "cut,copy,paste,pastetext,pasteword,|,search,replace,|,bullist,numlist,|,outdent,indent,blockquote,|,undo,redo,|,link,unlink,anchor,image,cleanup,help,code,|,insertdate,inserttime,preview,|,forecolor,backcolor",
		theme_advanced_buttons3 : "tablecontrols,|,hr,removeformat,visualaid,|,sub,sup,|,charmap,emotions,iespell,media,advhr,|,print,|,ltr,rtl,|,fullscreen",
		theme_advanced_buttons4 : "insertlayer,moveforward,movebackward,absolute,|,styleprops,|,cite,abbr,acronym,del,ins,attribs,|,visualchars,nonbreaking,template,pagebreak,restoredraft,visualblocks",
		theme_advanced_toolbar_location : "top",
		theme_advanced_toolbar_align : "left",
		theme_advanced_statusbar_location : "bottom",
		theme_advanced_resizing : true,

		// Example content CSS (should be your site CSS)
		content_css : "css/content.css",
                preformatted : true,
		// Drop lists for link/image/media/template dialogs
		template_external_list_url : "lists/template_list.js",
		external_link_list_url : "lists/link_list.js",
		external_image_list_url : "lists/image_list.js",
		media_external_list_url : "lists/media_list.js",
                valid_elements : "@[id|class|style|title|dir<ltr?rtl|lang|xml::lang|onclick|ondblclick|"
+ "onmousedown|onmouseup|onmouseover|onmousemove|onmouseout|onkeypress|"
+ "onkeydown|onkeyup],a[rel|rev|charset|hreflang|tabindex|accesskey|type|"
+ "name|href|target|title|class|onfocus|onblur],strong/b,em/i,strike,u,"
+ "#p,-ol[type|compact],-ul[type|compact],-li,br,img[longdesc|usemap|"
+ "src|border|alt=|title|hspace|vspace|width|height|align],-sub,-sup,"
+ "-blockquote,-table[border=0|cellspacing|cellpadding|width|frame|rules|"
+ "height|align|summary|bgcolor|background|bordercolor],-tr[rowspan|width|"
+ "height|align|valign|bgcolor|background|bordercolor],tbody,thead,tfoot,"
+ "#td[colspan|rowspan|width|height|align|valign|bgcolor|background|bordercolor"
+ "|scope],#th[colspan|rowspan|width|height|align|valign|scope],caption,-div,"
+ "-span,-code,-pre,address,-h1,-h2,-h3,-h4,-h5,-h6,hr[size|noshade],-font[face"
+ "|size|color],dd,dl,dt,cite,abbr,acronym,del[datetime|cite],ins[datetime|cite],"
+ "object[classid|width|height|codebase|*],param[name|value|_value],embed[type|width"
+ "|height|src|*],script[src|type],map[name],area[shape|coords|href|alt|target],bdo,"
+ "button,col[align|char|charoff|span|valign|width],colgroup[align|char|charoff|span|"
+ "valign|width],dfn,fieldset,form[action|accept|accept-charset|enctype|method],"
+ "input[accept|alt|checked|disabled|maxlength|name|readonly|size|src|type|value],"
+ "kbd,label[for],legend,noscript,optgroup[label|disabled],option[disabled|label|selected|value],"
+ "q[cite],samp,select[disabled|multiple|name|size],small,"
+ "textarea[cols|rows|disabled|name|readonly],tt,var,big",
		// Style formats
		style_formats : [
			{title : 'Bold text', inline : 'b'},
			{title : 'Red text', inline : 'span', styles : {color : '#ff0000'}},
			{title : 'Red header', block : 'h1', styles : {color : '#ff0000'}},
			{title : 'Example 1', inline : 'span', classes : 'example1'},
			{title : 'Example 2', inline : 'span', classes : 'example2'},
			{title : 'Table styles'},
			{title : 'Table row 1', selector : 'tr', classes : 'tablerow1'}
		],

		// Replace values for the template plugin
		template_replace_values : {
			username : "Some User",
			staffid : "991234"
		}

	});

</script>

<div id="form_update" class="div_form_content" >
    <h1>Edit article</h1>
    <p id="status1" style="font-size: 14px; color: red;"></p>
    <table>
        <tr>
            <td>Title(*)</td>
        </tr>
        <tr>
            
            <td><input type="text" class="input_form" id="s_title" value="<?php echo $row[1];?>" /></td>
        </tr>
    </table>
    <table>
        <tr>
            <td>Select category(*): 
                <select name="category" id="category" class="select">
                        <option value="0">- Select category - </option>
                        <?foreach($structure as $c) :?>
                        <?
                        $id=$c['id']; $sep=str_repeat("&nbsp;&nbsp;&nbsp;",($c['level']))."|__";
                        $selected = ($id==$data['category_id'])? 'selected' : '';
                        if($c['id']==$row['category_id']) {$selected='selected';}
                        ?>
                        <option value="<?=$id?>"  <?=$selected?>><?=$sep?><?=$categories[$id]['name']?></option>
                        <?endforeach?>
                </select>
            </td>
            <td>
                <input type="checkbox" id="ck_public" <?php if($row['customer_public']==1) {echo 'checked';}?> /> Public for customer
            </td>
        </tr>
    </table>
    <table>
        <tr>
            <td>Content(*):</td>
        </tr>
        <tr>
            
            <td><textarea id="elm1" name="elm1" rows="20" cols="80" style="width: 90%"><?php echo $row['detail'];?></textarea>

            </td>
        </tr>
    </table>
    <p style="margin-left: 100px"><input type="button" value="Update" onclick="Save()" class="button"> <input type="button" value="Reset" onclick="reset()" class="button"/> <br/></p>
    <div id="sending" style="margin-left: 20px;">
    <img src="../images/loading.gif" id="loading">
    </div>
</div>
<script type="text/javascript" src="<?=WEBSITE_URL?>/js/jquery.ui/jquery.ui.core.min.js"></script>
<script type="text/javascript" src="<?=WEBSITE_URL?>/js/jquery.ui/jquery.ui.widget.min.js"></script>
<script type="text/javascript" src="<?=WEBSITE_URL?>/js/jquery.ui/jquery.ui.datepicker.min.js"></script>
<script type="text/javascript" src="<?=WEBSITE_URL?>/js/jquery.ui/jquery-ui-timepicker-addon.js"></script>
<script type="text/javascript" src="<?=WEBSITE_URL?>/js/jquery.ui/jquery-ui-sliderAccess.js"></script>
<script type="text/javascript">
$(document).ready(function() {
    $('#sending').hide();
});  

function reset(){
    $('#s_title').val('');
    $('#ck_public').prop('checked',false);
    $('#elm1').val('');
}

function Save(){
	var id=<?php echo $row[0]; ?>;
    var title=$('#s_title').val();
    var check=0;
    if($('#ck_public').prop('checked')) check=1;
    var content=tinyMCE.get('elm1').getContent();
    var category=$('#category').val();
    //alert(title);
    if((title=="")||(content=="")||(category==0)){
        $("#status1").html('Fill all the required field (*)');
    }else{
        $('#sending').show();
        $.ajax({
          
          url: '<?=WEBSITE_URL?>/ajax.php',
          data: { m: 'manage_solution', a:'update_solution', id:id, title:title, check:check, content:content, 
              category:category},
          dataType:'json',
          success: function(data) {
            if (!data.success) {
                $("#status1").html('Update the article failed');
               //alert(data.error);
               return false;

            }else{
                //$('#noidung_tin').html('Đã lưu');
                $("#status1").html('Update the article success');
                $('#sending').hide();
                //$('#send').hide();
                //window.location("index.php?m=manage_solution");
            }
            //Update info
          } 
         
        });
    }

}
</script>
<style>
    table{
        width: 100%;
        margin: 10px;
        
    }
td
{
padding:3px;

text-align: left;
}
</style>